package cn.iocoder.yudao.module.system.controller.admin.gugu;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.gugu.vo.CollegeRecommendReqVO;
import cn.iocoder.yudao.module.system.controller.admin.gugu.vo.CollegeRecommendRespVO;
import cn.iocoder.yudao.module.system.service.gugu.CollegeRecommendationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 智能推荐大学测试控制器
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - 智能推荐大学测试")
@RestController
@RequestMapping("/system/college-recommendation-test")
@Validated
@Slf4j
public class CollegeRecommendationTestController {

    @Resource
    private CollegeRecommendationService collegeRecommendationService;

    @PostMapping("/test-recommend")
    @Operation(summary = "测试智能推荐大学")
    public CommonResult<CollegeRecommendRespVO> testRecommendColleges() {
        log.info("开始测试智能推荐大学接口");
        
        try {
            // 构造测试请求参数
            CollegeRecommendReqVO reqVO = new CollegeRecommendReqVO();
            reqVO.setPageNum(1);
            reqVO.setPageSize(10);
            reqVO.setYear(2024);
            reqVO.setProvince("江苏");
            reqVO.setScore(580);
            reqVO.setRanks(15000);
            reqVO.setSubjects("物理,化学,生物");
            reqVO.setClassify("物理");
            reqVO.setBatch("本科批");
            reqVO.setMinScore(570);
            reqVO.setMaxScore(590);
            
            // 设置偏好
            CollegeRecommendReqVO.PreferencesVO preferences = new CollegeRecommendReqVO.PreferencesVO();
            preferences.setRegions(Arrays.asList("江苏", "上海"));
            preferences.setSchoolTypes(Arrays.asList("985", "211"));
            preferences.setMajorCategories(Arrays.asList("工学"));
            reqVO.setPreferences(preferences);
            
            CollegeRecommendRespVO result = collegeRecommendationService.recommendColleges(reqVO);
            return success(result);
        } catch (Exception e) {
            log.error("测试智能推荐大学失败", e);
            return CommonResult.error(500, "推荐服务异常：" + e.getMessage());
        }
    }

    @GetMapping("/test-probability")
    @Operation(summary = "测试录取概率计算")
    public CommonResult<Double> testCalculateProbability() {
        try {
            Double probability = collegeRecommendationService.calculateAdmissionProbability(
                    15000, "test-school-uuid", "计算机科学与技术", "江苏", 2024, "物理");
            return success(probability);
        } catch (Exception e) {
            log.error("测试录取概率计算失败", e);
            return CommonResult.error(500, "计算失败：" + e.getMessage());
        }
    }

    @GetMapping("/test-type")
    @Operation(summary = "测试推荐类型判定")
    public CommonResult<String> testDetermineType(@RequestParam Double probability) {
        try {
            String type = collegeRecommendationService.determineRecommendationType(probability);
            return success(type);
        } catch (Exception e) {
            log.error("测试推荐类型判定失败", e);
            return CommonResult.error(500, "判定失败：" + e.getMessage());
        }
    }

    @GetMapping("/test-reason")
    @Operation(summary = "测试推荐理由生成")
    public CommonResult<String> testGenerateReason() {
        try {
            String reason = collegeRecommendationService.generateRecommendationReason(
                    "南京大学", "计算机科学与技术", 75.0, "WENTUO", Arrays.asList("985", "211"));
            return success(reason);
        } catch (Exception e) {
            log.error("测试推荐理由生成失败", e);
            return CommonResult.error(500, "生成失败：" + e.getMessage());
        }
    }
}
